﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using hcom;
using System.Data;

namespace hcms.Admin
{
	public partial class ArticleList : System.Web.UI.Page
	{
		public Model model = Global.model;
		public DataRowCollection rows;
		public DataRowCollection posrows;	// 当前位置
		public string cid;
		public int page;					// 页号，从1开始
		public int pages;					// 页数
		protected void Page_Load(object sender, EventArgs e)
		{
			cid = Request["cid"];
			page = Request["page"] == null ? 1 : int.Parse(Request["page"]);
			if (Page.IsPostBack)	// 页面提交
			{
				switch (cmd.Value)
				{
					case "delete":
						delete();
						break;

					case "itemlist":
						onitemlist();
						break;

					default:
						throw (new Exception("不可识别的提交命令: " + cmd.Value));
				}
			}

			int pagerows = 30;		// 每页行数
			rows = model.getArticleRows(cid, false, ref page, pagerows, ref pages);
			posrows = model.getCurrentPos(cid);
		}

		private void delete()
		{
			// 删除选择的文档，sel.Value格式“aid1, aid2, aid3,”， ** 同时删除生成的静态文档。
			model.delArticles(sel.Value, cid);
			//Response.Write("<script>alert('删除完毕。');</script>"); 用这个样式就没装进来。
			ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "alert('删除完毕。')", true);
		}

		private void onitemlist()
		{
			switch (itemlist.Value)
			{
				case "栏目":
					Response.Redirect("ColumnList.aspx?fixedpage=column&cid=" + cid);
					break;
				case "文档":
					break;
				case "评论":
					Response.Redirect("CommentList.aspx?fixedpage=column&cid=" + cid);
					break;
				default:
					throw (new Exception("不可识别的列表项: " + itemlist.Value));
			}
		}
	}
}